package Collert

import (
	"github.com/gin-gonic/gin"
	"models"
	"net/http"
	"strconv"
	"time"
	"types"
)

func ShopTimeAdd(c *gin.Context) {
	ShopId, _ := strconv.Atoi(c.PostForm("shop_id")) //商品id
	TimeZong := c.PostForm("time_zong")              //秒杀开始到结束的之间的
	MiaoCreate := c.PostForm("miao_create")          //开始时间
	MiaoStop := c.PostForm("miao_stop")              //结束时间
	pone := models.ShopTime{
		ShopId:     ShopId,
		TimeZong:   TimeZong,
		MiaoCreate: MiaoCreate,
		MiaoStop:   MiaoStop,
	}
	err := pone.ShopTime()
	if err != nil {
		c.JSON(http.StatusOK, types.Router{
			Code:     -1,
			Msg:      "添加失败",
			Database: nil,
		})
		return
	}
	c.JSON(http.StatusOK, types.Router{
		Code:     200,
		Msg:      "规划成功",
		Database: nil,
	})
	return
}

func ShopTimeInfo(c *gin.Context) {
	ShopId, _ := strconv.Atoi(c.PostForm("shop_id"))
	pone := models.ShopTime{ShopId: ShopId}
	res, err := pone.ShopTimeInfo()
	if err != nil {
		c.JSON(http.StatusBadRequest, types.Router{
			Code:     -1,
			Msg:      "未开始",
			Database: nil,
		})
		return
	}
	if res.MiaoCreate != time.DateTime {
		c.JSON(http.StatusBadRequest, types.Router{
			Code:     -1,
			Msg:      "未开始",
			Database: nil,
		})
		return
	}
	c.JSON(http.StatusOK, types.Router{
		Code:     200,
		Msg:      "已开始",
		Database: nil,
	})
}
